<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Relative Formats</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="datetime.formats.compound.html">« Compound Formats</a></li>
      <li style="float: right;"><a href="timezones.html">所支持的时区列表 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="datetime.formats.html">Supported Date and Time Formats</a></li>
    <li>Relative Formats</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="datetime.formats.relative" class="sect1">
  <h2 class="title">Relative Formats</h2>
  <p class="para">
   This page describes the different relative date/time formats that the
   <span class="classname"><a href="class.datetimeimmutable.html" class="classname">DateTimeImmutable</a></span>, <span class="classname"><a href="class.datetime.html" class="classname">DateTime</a></span>,
   <span class="function"><a href="function.date-create.html" class="function">date_create()</a></span>,
   <span class="function"><a href="function.date-create-immutable.html" class="function">date_create_immutable()</a></span>, and
   <span class="function"><a href="function.strtotime.html" class="function">strtotime()</a></span> parser understands.
  </p>
  
  <table class="doctable table">
   <caption><strong>Used Symbols</strong></caption>
   
    <thead>
     <tr>
      <th>Description</th>
      <th>Format</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td><code class="literal">dayname</code></td>
      <td>&#039;sunday&#039; | &#039;monday&#039; | &#039;tuesday&#039; | &#039;wednesday&#039; | &#039;thursday&#039; |
       &#039;friday&#039; | &#039;saturday&#039; | &#039;sun&#039; | &#039;mon&#039; | &#039;tue&#039; | &#039;wed&#039; | &#039;thu&#039; | &#039;fri&#039; |
       &#039;sat&#039;</td>
     </tr>

     <tr>
      <td><code class="literal">daytext</code></td>
      <td>&#039;weekday&#039; | &#039;weekdays&#039;</td>
     </tr>

     <tr>
      <td><code class="literal">number</code></td>
      <td>[+-]?[0-9]+</td>
     </tr>

     <tr>
      <td><code class="literal">ordinal</code></td>
      <td>&#039;first&#039; | &#039;second&#039; | &#039;third&#039; | &#039;fourth&#039; | &#039;fifth&#039; | &#039;sixth&#039; |
       &#039;seventh&#039; | &#039;eighth&#039; | &#039;ninth&#039; | &#039;tenth&#039; | &#039;eleventh&#039; | &#039;twelfth&#039; |
       &#039;next&#039; | &#039;last&#039; | &#039;previous&#039; | &#039;this&#039;</td>
     </tr>

     <tr>
      <td><code class="literal">reltext</code></td>
      <td>&#039;next&#039; | &#039;last&#039; | &#039;previous&#039; | &#039;this&#039;</td>
     </tr>

     <tr>
      <td><code class="literal">space</code></td>
      <td>[ \t]+</td>
     </tr>

     <tr>
      <td><code class="literal">unit</code></td>
      <td>&#039;ms&#039; | &#039;µs&#039; | (( &#039;msec&#039; | &#039;millisecond&#039; | &#039;µsec&#039; | &#039;microsecond&#039;
      | &#039;usec&#039; | &#039;sec&#039; | &#039;second&#039; | &#039;min&#039; | &#039;minute&#039; | &#039;hour&#039; | &#039;day&#039; |
      &#039;fortnight&#039; | &#039;forthnight&#039; | &#039;month&#039; | &#039;year&#039;) &#039;s&#039;?) | &#039;weeks&#039; |
      <code class="literal">daytext</code></td>
     </tr>

    </tbody>
   
  </table>

  
  <table class="doctable table">
   <caption><strong>Day-based Notations</strong></caption>
   
    <thead>
     <tr>
      <th>Format</th>
      <th>Description</th>
      <th>Examples</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>&#039;yesterday&#039;</td>
      <td>Midnight of yesterday</td>
      <td>&quot;yesterday 14:00&quot;</td>
     </tr>

     <tr>
      <td>&#039;midnight&#039;</td>
      <td>The time is set to 00:00:00</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td>&#039;today&#039;</td>
      <td>The time is set to 00:00:00</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td>&#039;now&#039;</td>
      <td>Now - this is simply ignored</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td>&#039;noon&#039;</td>
      <td>The time is set to 12:00:00</td>
      <td>&quot;yesterday noon&quot;</td>
     </tr>

     <tr>
      <td>&#039;tomorrow&#039;</td>
      <td>Midnight of tomorrow</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td>&#039;back of&#039; <code class="literal">hour</code></td>
      <td>15 minutes past the specified hour</td>
      <td>&quot;back of 7pm&quot;, &quot;back of 15&quot;</td>
     </tr>

     <tr>
      <td>&#039;front of&#039; <code class="literal">hour</code></td>
      <td>15 minutes before the specified hour</td>
      <td>&quot;front of 5am&quot;, &quot;front of 23&quot;</td>
     </tr>

     <tr>
      <td>&#039;first day of&#039;</td>
      <td>Sets the day of the first of the current month. This phrase is
       usually best used together with a month name following it as it only
       effects the current month</td>
      <td>&quot;first day of January 2008&quot;</td>
     </tr>

     <tr>
      <td>&#039;last day of&#039;</td>
      <td>Sets the day to the last day of the current month. This phrase is
       usually best used together with a month name following it as it only
       effects the current month</td>
      <td>&quot;last day of next month&quot;</td>
     </tr>

     <tr>
      <td><code class="literal">ordinal</code> <code class="literal">space</code> <code class="literal">dayname</code> <code class="literal">space</code> &#039;of&#039;</td>
      <td>Calculates the <code class="literal">x</code>-th week day of the current month.</td>
      <td>&quot;first sat of July 2008&quot;</td>
     </tr>

     <tr>
      <td>&#039;last&#039; <code class="literal">space</code> <code class="literal">dayname</code> <code class="literal">space</code> &#039;of&#039;</td>
      <td>Calculates the <em class="emphasis">last</em> week day of the current month.</td>
      <td>&quot;last sat of July 2008&quot;</td>
     </tr>

     <tr>
      <td><code class="literal">number</code> <code class="literal">space</code>? (<code class="literal">unit</code> | &#039;week&#039;)</td>
      <td>Handles relative time items where the value is a number.</td>
      <td>&quot;+5 weeks&quot;, &quot;12 day&quot;, &quot;-7 weekdays&quot;</td>
     </tr>

     <tr>
      <td><code class="literal">ordinal</code> <code class="literal">space</code> <code class="literal">unit</code></td>
      <td>Handles relative time items where the value is text.</td>
      <td>&quot;fifth day&quot;, &quot;second month&quot;</td>
     </tr>

     <tr>
      <td>&#039;ago&#039;</td>
      <td>Negates all the values of previously found relative time items.</td>
      <td>&quot;2 days ago&quot;, &quot;8 days ago 14:00&quot;, &quot;2 months 5 days ago&quot;, &quot;2 months ago 5 days&quot;, &quot;2 days ago&quot;</td>
     </tr>

     <tr>
      <td><code class="literal">dayname</code></td>
      <td>
       Moves to the next day of this name. (See <a href="datetime.formats.relative.html#datetime.formats.relative.dayname-note" class="link">note</a>)
      </td>
      <td>&quot;Monday&quot;</td>
     </tr>

     <tr>
      <td><code class="literal">reltext</code> <code class="literal">space</code> &#039;week&#039;</td>
      <td>Handles the special format &quot;weekday + last/this/next week&quot;.</td>
      <td>&quot;Monday next week&quot;</td>
     </tr>

    </tbody>
   
  </table>

  
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    Relative statements are always processed <em class="emphasis">after</em>
    non-relative statements. This makes &quot;+1 week july 2008&quot; and &quot;july
    2008 +1 week&quot; equivalent.
   </p>
   <p class="para">
    Exceptions to this rule are: &quot;yesterday&quot;, &quot;midnight&quot;, &quot;today&quot;, &quot;noon&quot;
    and &quot;tomorrow&quot;. Note that &quot;tomorrow 11:00&quot; and &quot;11:00 tomorrow&quot;
    are different. Considering today&#039;s date of &quot;July 23rd, 2008&quot; the
    first one produces &quot;2008-07-24 11:00&quot; where as the second one
    produces &quot;2008-07-24 00:00&quot;. The reason for this is that those
    five statements directly influence the current time.
   </p>
   <p class="para">
    Keywords such as &quot;first day of&quot; depend on the context in which the
    relative format string is used. If used with a static method or function,
    the referent is the current system timestamp. However, if used in
    <span class="function"><a href="datetime.modify.html" class="function">DateTime::modify()</a></span> or
    <span class="function"><a href="datetimeimmutable.modify.html" class="function">DateTimeImmutable::modify()</a></span>, the referent is the object
    on which the <code class="literal">modify()</code> method is called.
   </p>
  </p></blockquote>
  
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para" id="datetime.formats.relative.dayname-note">
    Observe the following remarks when the current day-of-week is the
    same as the day-of-week used in the date/time string. The current
    day-of-week could have been (re-)calculated by non-relative parts of
    the date/time string however.
   </p>
   <ol type="1">
    <li class="listitem">
     <span class="simpara">
      &quot;<code class="literal">dayname</code>&quot; does <em class="emphasis">not</em> advance to
      another day. (Example: &quot;Wed July 23rd, 2008&quot; means &quot;2008-07-23&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<code class="literal">number</code> <code class="literal">dayname</code>&quot; does
      <em class="emphasis">not</em> advance to another day. (Example: &quot;1
      wednesday july 23rd, 2008&quot; means &quot;2008-07-23&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<code class="literal">number</code> week <code class="literal">dayname</code>&quot; will
      first add the number of weeks, but does <em class="emphasis">not</em>
      advance to another day. In this case &quot;<code class="literal">number</code>
      week&quot; and &quot;<code class="literal">dayname</code>&quot; are two distinct blocks.
      (Example: &quot;+1 week wednesday july 23rd, 2008&quot; means &quot;2008-07-30&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<code class="literal">ordinal</code> <code class="literal">dayname</code>&quot;
      <em class="emphasis">does</em> advance to another day. (Example &quot;first
      wednesday july 23rd, 2008&quot; means &quot;2008-07-30&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<code class="literal">number</code> week <code class="literal">ordinal</code>
      <code class="literal">dayname</code>&quot; will first add the number of
      weeks, and then <em class="emphasis">advances</em> to another
      day. In this case &quot;<code class="literal">number</code> week&quot; and
      &quot;<code class="literal">ordinal</code> <code class="literal">dayname</code>&quot; are two
      distinct blocks. (Example: &quot;+1 week first wednesday july 23rd,
      2008&quot; means &quot;2008-08-06&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<code class="literal">ordinal</code> <code class="literal">dayname</code> &#039;of&#039; &quot;
      does <em class="emphasis">not</em> advance to another day. (Example:
      &quot;first wednesday of july 23rd, 2008&quot; means &quot;2008-07-02&quot; because
      the specific phrase with &#039;of&#039; resets the day-of-month to &#039;1&#039; and
      the &#039;23rd&#039; is ignored here).
     </span>
    </li>
   </ol>
   <p class="para">
    Also observe that the &quot;of&quot; in &quot;<code class="literal">ordinal</code>
    <code class="literal">space</code> <code class="literal">dayname</code>
    <code class="literal">space</code> &#039;of&#039; &quot; and &quot;&#039;last&#039; <code class="literal">space</code>
    <code class="literal">dayname</code> <code class="literal">space</code> &#039;of&#039; &quot; does
    something special.
   </p>
   <ol type="1">
    <li class="listitem">
     <span class="simpara">
      It sets the day-of-month to 1.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<code class="literal">ordinal</code> <code class="literal">dayname</code> &#039;of&#039; &quot; does
      <em class="emphasis">not</em> advance to another day. (Example: &quot;first
      tuesday of july 2008&quot; means &quot;2008-07-01&quot;).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;<code class="literal">ordinal</code> <code class="literal">dayname</code> &quot;
      <em class="emphasis">does</em> advance to another day. (Example: &quot;first
      tuesday july 2008&quot; means &quot;2008-07-08&quot;, see also point 4 in the
      list above).
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;&#039;last&#039; <code class="literal">dayname</code> &#039;of&#039; &quot; takes the last
      <code class="literal">dayname</code> of the current month. (Example: &quot;last
      wed of july 2008&quot; means &quot;2008-07-30&quot;)
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      &quot;&#039;last&#039; <code class="literal">dayname</code>&quot; takes the last
      <code class="literal">dayname</code> from the current day. (Example: &quot;last
      wed july 2008&quot; means &quot;2008-06-25&quot;; &quot;july 2008&quot; first sets the
      current date to &quot;2008-07-01&quot; and then &quot;last wed&quot; moves to the
      previous Wednesday which is &quot;2008-06-25&quot;).
     </span>
    </li>
   </ol>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    Relative month values are calculated based on the length of months that
    they pass through. An example would be &quot;+2 month 2011-11-30&quot;, which would
    produce &quot;2012-01-30&quot;. This is due to November being 30 days in length, and
    December being 31 days in length, producing a total of 61 days.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    <code class="literal">number</code> is an <em class="emphasis">integer</em> number; if a
    decimal number is given, the dot (or comma) is likely interpreted as delimiter.
    For instance, <code class="literal">&#039;+1.5 hours&#039;</code> is parsed like
    <code class="literal">&#039;+1 5 hours&#039;</code>, not as <code class="literal">&#039;+1 hour +30 minutes&#039;</code>.
   </p>
  </p></blockquote>
  
  <div class="sect2">
   <h3 class="title">更新日志</h3>
   <p class="para">
    <table class="doctable informaltable">
     
      <thead>
       <tr>
        <th>版本</th>
        <th>说明</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>7.0.8</td>
        <td>
         Weeks always start on monday. Formerly, sunday would also be considered
         to start a week.
        </td>
       </tr>

      </tbody>
     
    </table>

   </p>
  </div>
 </div></div></div></body></html>